package com.vkmessenger.core.localcache;

import java.util.HashSet;
import java.util.Set;

/**
 * Created by IntelliJ IDEA.
 * User: Evgeniy Krasko
 * Date: 21.06.12
 * Time: 15:56
 */


/**
 * Thread-safe
 */
public abstract class ListenableEntity {
    private Set<Notifiable> listeners = new HashSet<Notifiable>();

    public synchronized void addListener(Notifiable listener) {
        listeners.add(listener);
    }

    public synchronized void removeListener(Notifiable listener) {
        listeners.remove(listener);
    }

    public synchronized void stateChanged(Object invoker) {
        for (Notifiable listener : listeners) {
            listener.notify(invoker);
        }
    }
}
